package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.goods.GoodsCartBO;
import com.ymk.bo.goods.GoodsSkuBO;
import com.ymk.core.code.cmd.GoodsCmdCode;
import com.ymk.service.IGoodsCartService;
import com.ymk.service.IGoodsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class GoodsCartListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId", sign.getMchId())
                .addParam("userId", sign.getUserId())
                .addParam("loadGoods",true)
                .addParam("loadGoodsSku",true)
                .setReturnStruct(sign.getReturnStruct());
        List<GoodsCartBO> goodsCartBOList = this.goodsCartService.list(paramsBuilder.build());

        respSign.setSource(super.getSource(goodsCartBOList));
        return respSign;
    }

    @Override
    public CmdSign executeStore(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId", sign.getMchId())
                .addParam("userId", sign.getUserId())
                .addParam("loadGoods",true)
                .addParam("loadGoodsSku",true)
                .setReturnStruct(sign.getReturnStruct());

        List<GoodsCartBO> goodsCartBOList = this.goodsCartService.list(paramsBuilder.build());

        respSign.setSource(super.getSource(goodsCartBOList));
        return respSign;
    }

    @Override
    public CmdSign executeServer(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        Map param = super.getData(sign, Map.class);
        List<GoodsCartBO> goodsCartBOList = this.goodsCartService.list(param);

        respSign.setSource(super.getSource(goodsCartBOList));
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return GoodsCmdCode.GOODS_CART_LIST;
    }

    @Autowired
    private IGoodsCartService goodsCartService;
}